package com.jidu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jidu.common.annotation.RepeatSubmit;
import com.jidu.common.utils.poi.ExcelUtil;
import com.jidu.domain.StudentClassTimeRel;
import com.jidu.service.IStudentClassTimeRelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jidu.common.annotation.Log;
import com.jidu.common.core.controller.BaseController;
import com.jidu.common.core.domain.AjaxResult;
import com.jidu.common.enums.BusinessType;
import com.jidu.common.core.page.TableDataInfo;

/**
 * 学生上课记录签到Controller
 * 
 * @author xuliang
 * @date 2024-07-25
 */
@Slf4j
@Api(tags = "学生上课记录签到 controller")
@RestController
@RequestMapping("/class/time/rel")
public class StudentClassTimeRelController extends BaseController
{
    @Autowired
    private IStudentClassTimeRelService studentClassTimeRelService;

    /**
     * 查询学生上课记录签到列表
     */
    @PreAuthorize("@ss.hasPermi('system:rel:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentClassTimeRel studentClassTimeRel)
    {
        startPage();
        List<StudentClassTimeRel> list = studentClassTimeRelService.selectStudentClassTimeRelList(studentClassTimeRel);
        return getDataTable(list);
    }

    /**
     * 导出学生上课记录签到列表
     */
    @PreAuthorize("@ss.hasPermi('system:rel:export')")
    @Log(title = "学生上课记录签到", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentClassTimeRel studentClassTimeRel)
    {
        List<StudentClassTimeRel> list = studentClassTimeRelService.selectStudentClassTimeRelList(studentClassTimeRel);
        ExcelUtil<StudentClassTimeRel> util = new ExcelUtil<StudentClassTimeRel>(StudentClassTimeRel.class);
        util.exportExcel(response, list, "学生上课记录签到数据");
    }

    /**
     * 获取学生上课记录签到详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(studentClassTimeRelService.selectStudentClassTimeRelById(id));
    }

    /**
     * 新增学生上课记录签到
     */
    @PreAuthorize("@ss.hasPermi('system:rel:add')")
    @Log(title = "学生上课记录签到", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentClassTimeRel studentClassTimeRel)
    {
        return toAjax(studentClassTimeRelService.insertStudentClassTimeRel(studentClassTimeRel));
    }

    /**
     * 修改学生上课记录签到
     */
    @PreAuthorize("@ss.hasPermi('system:rel:edit')")
    @Log(title = "学生上课记录签到", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentClassTimeRel studentClassTimeRel)
    {
        return toAjax(studentClassTimeRelService.updateStudentClassTimeRel(studentClassTimeRel));
    }

    /**
     * 删除学生上课记录签到
     */
    @PreAuthorize("@ss.hasPermi('system:rel:remove')")
    @Log(title = "学生上课记录签到", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(studentClassTimeRelService.deleteStudentClassTimeRelByIds(ids));
    }

    /**
     * 学员签到:  courseStudentId: 学生课程关系id    classTimeId：班级上课时间安排表id type:0 签到    1请假
     */
    @RepeatSubmit
    @PostMapping("/student/sign")
    @ApiOperation(value = "学员签到/请假")
    public AjaxResult sign(@RequestParam(value = "courseStudentId") Long courseStudentId,@RequestParam(value = "classTimeId") Long classTimeId,@RequestParam(value = "type")String type){
        return AjaxResult.success(studentClassTimeRelService.sign(courseStudentId,classTimeId,type));
    }

    @ApiOperation(value = "学员上课记录")
    @GetMapping("/classTime/list")
    public AjaxResult classTimeList(@RequestParam(value = "studentId")Long studentId){
        return AjaxResult.success(studentClassTimeRelService.classTimeList(studentId));
    }
}
